package cn.kgc.ssm.instener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author: hengge
 * @version: v1.0
 * @DATE: 2022/10/22
 * 监听applicaton域对象的创建
 */
@WebListener
public class MyContextListener implements ServletContextListener {

    //全局域对象的创建
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //获取项目的虚拟路径，存储在应用上下文对象中
        String contextPath = sce.getServletContext().getContextPath();
        //将获取到的虚拟路径 放入application域对象中
        sce.getServletContext().setAttribute("bp", contextPath);
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
